package com.wjb.xietong.ota;

import java.util.ArrayList;
import java.util.List;

import com.wjb.xietong.R;
import com.wjb.xietong.component.ActManager;
import com.wjb.xietong.component.AppGlobal;
import com.wjb.xietong.ota.login.OTALogin;
import com.wjb.xietong.util.PreferencesService;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;

public class OTAStartupShow extends Activity{

	private List<View> lists = new ArrayList<View>();
	private ImgAdaper imgAdpt = null;
	private ViewPager viewPager;
	
	private Button btStart = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.app_startup_show);
		
		
		lists.add(getLayoutInflater().inflate(R.layout.app_startup_1, null));
		lists.add(getLayoutInflater().inflate(R.layout.app_startup_2, null));
		lists.add(getLayoutInflater().inflate(R.layout.app_startup_3, null));
		
		
		
		
		imgAdpt = new ImgAdaper(lists);
	
		viewPager = (ViewPager) findViewById (R.id.viewPager);
        viewPager.setAdapter(imgAdpt);
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            
            @Override
            public void onPageSelected(int arg0) {   
            	if (arg0 == 2){
            		btStart.setVisibility(View.VISIBLE);
            	}
            	else{
            		btStart.setVisibility(View.INVISIBLE);
            	}
            }

			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
				
			}
        });
        
        btStart = (Button)findViewById(R.id.idBTStatup);
        btStart.setOnClickListener(new Button.OnClickListener(){

			@Override
			public void onClick(View arg0) {
				
				Intent intent = new Intent(OTAStartupShow.this, OTALogin.class);
				startActivity(intent);
				
				PreferencesService preferences = new PreferencesService(AppGlobal
						.getInstance().getBaseContext());
				preferences.saveUserLogin("yes");
				
				finish();	
				
				
			}
        	
        });
	}

}
